package br.com.hotel.dao;

import br.com.hotel.entity.Sessao;
import br.com.hotel.entity.TabelaPreco;

public class SessaoDAO extends GenericJpaRepository<Sessao, Long> {

	
	
	
	public SessaoDAO() throws ClassNotFoundException{
		createEntityManager();
	}

	public  Object getSession(String param) {
		
		Sessao sessao = getSessaoObject(param);
		if(sessao==null)
			return null;
		else
			return sessao.getValue();

	}
	
	
	private  Sessao getSessaoObject(String param) {
		javax.persistence.Query query = getEntityManager().createQuery("SELECT p FROM Sessao p WHERE p.param = '"+param +
				"' ");
		if(query.getResultList().size()==0)
			return null;
		else
			return (Sessao)query.getSingleResult();

	}

	public  void setSession(String param, String value) {
		Sessao sessao =  getSessaoObject(param);
		if(sessao==null)
			sessao = new Sessao();
		sessao.setParam(param);
		sessao.setValue(value);
		begin();
		save(sessao);
		commit();
	}
}
